<?php
	class Pages extends CI_Controller{
		function __constructor(){
			parent::__constructor();
                        
                }
		
		function index(){
			$this->mytemplate->dressing('pages/index',NULL);
		}
		
		function kategori_komoditas(){
                
		}
		
		function registration(){
						  var_dump($this->session->flashdata('test'));
			//$this->mytemplate->dressing('pages/registration',NULL);
		}
		
		function katalog(){
			
		}
		
		function jadwalLelang(){
			
		}
		
		function panduan(){
			
		}

                function user_verification(){

                        //$this->mytemplate->dressing('pages/user_verification',NULL);
		}
		
		function login(){
                        $this->mytemplate->dressing('pages/login',NULL);
		}
		
		function forget_password(){
			$this->mytemplate->dressing('pages/forget_password',NULL);
		}
                function change_password(){
                        $this->mytemplate->dressing_secure('pages/change_password',NULL);
		}

        function process_login()
        {
			$state = false;
            $flash = array();
                    
            if(!$this->input->post('recaptcha_response_field')){
                        $resp = recaptcha_check_answer ('6LfVjM0SAAAAAE0f788F1M8qtKmrPGJ5aW6F8JXj',
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);
                        

                        if(!$resp->is_valid){
                            if ($this->input->post('username') && $this->input->post('password')) {
                                $userlogin = $this->admin_model->SelectUserLogin($this->input->post('username'),md5($this->input->post('password')));

                                if(isset($userlogin[0]['OK'])){
                                    if(!$userlogin[0]['IsVerified']){
                                        $flash = getmessagecode(8);
                                    }
                                    else if(!$userlogin[0]['IsActive']){
                                        $flash = getmessagecode(7);
                                    }
                                    else{
                                        $state = true;

                                        $this->admin_model->UpdateUserLogin(1,$userlogin[0]['UserId']);
                                        $params = array(
                                            'UserId'=>$userlogin[0]['UserId'],
                                            'UserLogin'=>$userlogin[0]['UserLogin'],
                                            'UserName'=>$userlogin[0]['UserName'],
                                            'LastLogin'=>$userlogin[0]['LastLoginDate'],
                                            'TimeZone'=>date_default_timezone_get()
                                        );
                                        
                                        $this->session->set_userdata('UserInfo',$params);
                                        $this->session->set_userdata('site_page',$this->system_model->get_defaultpage($userlogin[0]['UserId']));
                                    }

                                }
                                else
                                {
                                    $flash = $userlogin;
                                }
                            }
                            else {
                                $flash = getmessagecode(2);
                            }
                        }
                        else{
                            $flash = getmessagecode(3);
                        }
                    }
                    else{
                        $flash = getmessagecode(4);
                    }

                    
                    if(!$state){
                        $formvalue = array(	
							'username'=>$this->input->post('username'),
                            'flashmessage'=>$flash
						);
			
                        $this->session->set_flashdata('formvalue',$formvalue);
				
						redirect('pages/login');

                    }else{
                        redirect('admins/index');
                    }

		}
                
        function logout()
        {
			$userid = $this->session->userdata('UserInfo');
			$this->admin_model->UpdateUserLogin(0,$userid['UserId']);
			
			$userinfo = array(
				'UserId'=>0,
				'UserLogin'=>'Anonymous',
				'TimeZone'=>date_default_timezone_get()
			);
			
			$this->session->set_userdata('UserInfo',$userinfo);
            $this->session->set_userdata('site_page',$this->system_model->get_defaultpage(0));
            
            redirect('pages/index');
		}        
                
	}
	
	
/* End of file pages.php */
/* Location: ./application/controllers/pages.php */
